package org.mtmi.ui.drawables;

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Path;
import org.mtmi.ui.GraphicUtil;
import org.mtmi.ui.controls.Control;
import org.mtmi.ui.scenes.COLOR;

/**
 * Display an image of knob color .
 */
public class SliderThumbDrawable extends AbstractColorDrawable 
{
	
	/** caller is responsible to dispose color */
	public SliderThumbDrawable( Color clr ) {
		super( clr );
	}
	
	@Override
	public void paint( GC gc, int x, int y, int width, int height, int state ) {
		//a square:
		int d = Math.min( width, height );
		
		int tx = x+(width-d)/2;
		int ty = y+(height-d)/2;
		int r = (int)(0.5f*d);
		
		//note: draw vertical thumb (by choice)
		Path outline = GraphicUtil.getRoundRectangle(gc, tx, ty, d, d, r, r );
		
		gc.setBackground( color );
		gc.fillPath( outline );
		gc.setForeground( COLOR.grey20 );
		int bw = Control.borderWidth;
		gc.setLineWidth( bw/2 );
		gc.drawPath( outline );
		
		int xl = tx+bw+1;
		int xr = tx+d-bw-1;
		int y1  = ty+d/2;
		int y2  = y1 - bw/2;
		if( xl<xr ) {
			gc.setForeground( COLOR.grey20 );
			gc.drawLine( xl, y1, xr, y1 );
			gc.setForeground( COLOR.grey70 );
			gc.drawLine( xl, y2, xr, y2 );
		}
		outline.dispose();
	}

}
